package Solution201_220;

/**
 * 欢乐数
 */
public class Solution202 {
    public boolean isHappy(int n) {
        int slow=n;
        int fast=n;
        do {
            slow=buildNum(slow);
            fast=buildNum(fast);
            fast=buildNum(fast);
        }while (slow!=fast);
        if(slow==1){
            return true;
        }
        return false;
    }

    private int buildNum(int n){
        int num=0;
        while (n!=0){
            num+=(n%10)*(n%10);
            n=n/10;
        }
        return num;
    }

}
